package com.samphanie.ane.core.security.oauth2;

import lombok.val;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;

import java.util.HashMap;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2021/3/12 11:24
 */
@Configuration
public class CustomJwtTokenConverter extends JwtAccessTokenConverter {

    public CustomJwtTokenConverter(UserDetailsService userDetailsService) {
        super.setAccessTokenConverter(new CustomTokenConverter(userDetailsService));
    }


//    @Override
//    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
//        if (authentication != null && authentication.getPrincipal() instanceof User) {
//            val additionalInfo = new HashMap<String, Object>();
//            val user = (User) authentication.getPrincipal();
//            additionalInfo.put("email", user.getEmail());
//            additionalInfo.put("mobile", user.getMobile());
//            additionalInfo.put("name", user.getName());
//            ((DefaultOAuth2AccessToken) accessToken)
//                    .setAdditionalInformation(additionalInfo);
//        }
//        val token = super.enhance(accessToken, authentication);
//        ((DefaultOAuth2AccessToken) token).setAdditionalInformation(new HashMap<>());
//        return super.enhance(accessToken, authentication);
//    }
}
